//import {getxm,getxm1} from "api.js";
//import zzjg from "../../../../../themes/admin_default/xmgl/assets/utils/zzjg.js";
//import role from "../../../../../themes/admin_default/xmgl/assets/utils/role.js";
//import user from "../../../../../themes/admin_default/xmgl/assets/utils/userpublic.js";
//import { unixtimetostr } from "../../../../../themes/admin_default/xmgl/assets/utils/tools.js";

//import {} from 'https://unpkg.com/video.js@7.10.2/dist/video.min.js';

import tools from "../../public/utils/tools.js";
import { unixtimetostr1 } from "../../public/utils/tools.js";
import api from "../../public/utils/api.js";


axios.defaults.headers.post['Content-Type'] = 'application/json';

var Event = new Vue();//定义一个空的Vue实例 ，专门用来进行组件间通信

// 注册
Vue.component('xtest', {
    props: ['post'],
    template: '<h1>自定义组件!</h1>',
    data: function () {
        return {
            rootResourceTypeList: []
        };
    },
    mounted: function () {
        this.getRootResourceTypeList();
    },
    methods: {
    },
});

//挂载layer组件
Vue.use(LayerVue, {
    //此项设置置顶窗口的初始值，默认为100，一般无需配置，和其他组件冲突时可在此配置
    // 非置顶窗口请使用时单独设置
    zIndex: 100,
    //全局配置窗口皮肤
    skin: {
        //具体参数参见配置项：skin
    },
    //控制台打印相关信息
    log: true
});

var vm = new Vue({
    el: '#app',
    components: {
        // 局部注册，标签名称comp1
    },
    created() {
        this.setTime();
    },
    beforeDestroy() {
        clearInterval(this.timer);  // 清除定时器
        this.timer = null;
    },
    mounted: function () {
        // 访问组件的 DOM 元素
        //console.log(this.$el)
        let that = this;
        // 使用 $nextTick 方法访问父组件的数据
        this.$nextTick(() => {
            console.log('使用 $nextTick 方法访问父组件的数据', this.form)
            //console.log('unionid:', this.$refs.union_id.value);
            this.init_data();

            let player = videojs('my-player', this.playOptions, function onPlayerReady() {
                videojs.log('播放器准备好了!');
                // In this context, `this` is the player that was created by Video.js.
                this.play();
                this.on('ended', function () {
                    videojs.log('播放结束!');
                });
            });

        })
        // 监听数据变化
        this.$watch('data', () => {
            console.log('data changed');
        })
        // 在组件销毁时取消异步操作
        this.$once('hook:beforeDestroy', () => {
            that.cancelAsyncTask();
        })

    },
    data: function () {
        return {

            activeIndex: '2',

            value1: 0,
            title1: "总登录次数",
            title2: "当前在线人数",
            value2: 0,

            playOptions: {
                autoplay: "muted",
                muted: true,
                preload: "auto",
                //width:"800",
                height: "600",
                //fluid: true
            },
        }
    },
    methods: {
        unixtimetostr1,
        handleSelect(key, keyPath) {
            console.log(key, keyPath);
        },
        setTime() {
            //每隔120秒钟运行一次保存方法
            this.timer = setInterval(() => {
                this.init_data();
            }, 120000)
        },
    },
});

//vm.unixtimetostr1 = tools.unixtimetostr1;
vm.init_data = function () {
    let that = this;
    //
    api.getDLNum().then((res) => {
        console.log(res.data);
        that.value1 = res.data;
    }).catch((res) => {
        console.log(res.data);
    });

    api.getOnlineUsers().then((res) => {
        console.log(res.data);  //[{onlineusernum: 144}]
        that.value2 = res.data.onlineusernum;
    }).catch((res) => {
        console.log(res.data);
    });
}
vm.upOnlineUserStatus = function () {
    api.upOnlineUserStatus().then((res) => {
        console.log("upOnlineUserStatus:" + res.data);
    }).catch((res) => {
        console.log("upOnlineUserStatus:" + res.data);
    });
}



